/**
 * 医生病例表格初始化
 */
var CaseTableList = {
    id: "CaseTableList",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CaseTableList.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'customerId', field: 'customerId', visible: false, align: 'center', valign: 'middle'},
        {title: '客户姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true},
        {title: '主诉', field: 'zhushu', align: 'center', valign: 'middle', sortable: true},
        {title: '现病史', field: 'nowMedicalHistory', align: 'center', valign: 'middle', sortable: true},
        {title: '既病史', field: 'beforeMedicalHistory', align: 'center', valign: 'middle', sortable: true},
        {title: '口腔检查', field: 'mouthCheck', align: 'center', valign: 'middle', sortable: true},
        {title: '诊断', field: 'diagnose', align: 'center', valign: 'middle', sortable: true},
        {title: '治疗计划', field: 'remedyPlan', align: 'center', valign: 'middle', sortable: true},
        {title: '处置', field: 'dispose', align: 'center', valign: 'middle', sortable: true},
        {title: '医嘱', field: 'doctorAdvice', align: 'center', valign: 'middle', sortable: true},
        {
            title: '操作', field: 'checkStatus', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                    return "<a href='javascript:;' onclick='CaseTableList.caseDetails(" + '"' + row.id + '"' + ")'>[详情]</a>"+
                        "<a href='javascript:;' onclick='CaseTableList.updateCase(" + '"' + row.id + '"' + ")'>[编辑]</a>"
            }
        },
    ]
    return columns;
};


/**
 * 病例详情
 * @param id
 */
CaseTableList.caseDetails = function (id) {
    var index = layer.open({
        type: 2,
        title: '病例详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/case_details/' + id
    });
    this.layerIndex = index;
}

/**
 * 修改病例详情
 * @param id
 */
CaseTableList.updateCase = function (id) {
    var customerId=document.getElementById("customerId").value;
    var cri=id+","+customerId;
    var index = layer.open({
        type: 2,
        title: '病例修改',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/update/' + cri
    });
    this.layerIndex = index;
};

/**
 * 关闭此对话框
 */
CaseTableList.close = function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

/**
 * 新增病历n
 * @param id
 */
CaseTableList.addCase = function () {
    var customerId = $("#customerId").val();
    var customerStatus = $("#customerStatus").val();
    var cc = customerId + "," + customerStatus
    var index = layer.open({
        type: 2,
        title: '全部病历',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/add/' + cc
    });
    this.layerIndex = index;
}

/**
 * 打印病历n
 * @param id
 */
CaseTableList.prints = function (ids) {
    console.log(ids);
    var index = layer.open({
        type: 2,
        title: '打印病历',
        area: ['70%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_print/' + ids
    });
    this.layerIndex = index;
}

/**
 * 复诊打印病历n
 * @param id
 */
CaseTableList.printss = function (ids) {
    console.log(ids);
    var index = layer.open({
        type: 2,
        title: '打印病历',
        area: ['70%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_prints/' + ids
    });
    this.layerIndex = index;
}

/**
 * 检查是否选中
 */
CaseTableList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CaseTableList.seItem = selected[0];
        return true;
    }
};


/**
 * 查询预约客户列表
 */
CaseTableList.search = function () {
    CaseTableList.table.refresh();
};
/**
 * 检查是否选中
 */
CaseTableList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CaseTableList.seItem = selected[0];
        return true;
    }
};

/**
 * 打印
 */
CaseTableList.print = function () {

    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '打印',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctorLooked/to_print/' + CaseTableList.seItem.id // 传入选中行的客户ID

        });
        this.layerIndex = index;
    }
}

$(function () {
    // var defaultColunms = CaseTableList.initColumn();
    // var customerId =$("#customerId").val();
    // var table = new BSTable(CaseTableList.id, "/doctorLooked/caseTableList/"+customerId, defaultColunms);
    // table.setPaginationType("client");//客户端分页
    // CaseTableList.table = table.init();
    // CaseTableList.search();
});
